﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using FubiManger.UI;

namespace FubiManger.Controls
{
    ////ToolboxItem用于控制是否添加自定义控件到工具箱，true添加，false不添加
    //[System.ComponentModel.ToolboxItem(true)]
    partial class rulecontrol : Smobiler.Core.Controls.MobileUserControl
    {
        public rulecontrol() : base()
        {
            //This call is required by the SmobilerUserControl.
            InitializeComponent();
        }
        /// <summary>
        /// 1代表添加新规则
        /// </summary>
        public string status { get; set; }
        /// <summary>
        /// 商户ID
        /// </summary>
        public string merchantid { get; set; }
        /// <summary>
        /// 规则标题
        /// </summary>
        public string ruletitle { get; set; }
        /// <summary>
        /// 规则
        /// </summary>
        public string rule { get; set; }
        /// <summary>
        /// 编号
        /// </summary>
        public int index { get; set; }
        /// <summary>
        /// 规则ID
        /// </summary>

        public string ruleid { get; set; }

        private void rulecontrol_Load(object sender, EventArgs e)
        {
            if (status == "1")
            {
                txtrule.ReadOnly = false;
                lblruletitle.Text = "规则" + (index + 1).ToString();
                
                btnsave.Visible = true;
            }
            else
            {
                txtrule.ReadOnly = true;
                panel1.TouchDisabled = false;
                txtrule.Text = rule;
                lblruletitle.Text = ruletitle;
            }
        }

        private void txtrule_TextChanged(object sender, EventArgs e)
        {
            //if (status == "1")
            //{
            //    btnsave.Visible = true;
            //}
        }

        private void btnsave_Press(object sender, EventArgs e)
        {
            if (packetruleDal.Addreule(merchantid, txtrule.Text, lblruletitle.Text) > 0)
            {
                //txtrule.ReadOnly = true;
                //btnsave.Visible = false;
                //panel1.TouchDisabled = false;
                ((AddruleForm)this.Form).Refsh();
            }
        }
        /// <summary>
        /// 选择规则
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void panel1_Press(object sender, EventArgs e)
        {
            ((AddruleForm)this.Form).Setrule(ruletitle,ruleid);
        }
    }
}